﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;

namespace HalconDemoWPF0324002.Extensions
{
    public static class DrawingObjExtensions
    {
        /// <summary>
        /// 根据Htuples生成区域
        /// </summary>
        /// <param name="drawinfo"></param>
        /// <returns></returns>
        public static HObject GenObject(this HDrawingObjectInfo drawinfo)
        {
            HObject hObject = null;
            switch (drawinfo.type)
            {
                case "rectangle1":
                    {
                        HOperatorSet.GenRectangle1(out hObject, drawinfo.Tuples[0], drawinfo.Tuples[1], drawinfo.Tuples[2], drawinfo.Tuples[3]);
                    }
                    break;
                case "circle":
                    {
                        HOperatorSet.GenCircle(out hObject, drawinfo.Tuples[0], drawinfo.Tuples[1], drawinfo.Tuples[2]);
                    }
                    break;
                default:
                    break;
            }
            return hObject;
        }




        public static HTuple[] GetTuples(this HDrawingObject obj)
        {

            HTuple[] hts = null;
            string type = obj.GetDrawingObjectParams("type");
            switch (type)
            {
                case "rectangle1":
                    {

                        var row1 = obj.GetDrawingObjectParams("row1");
                        var row2 = obj.GetDrawingObjectParams("row2");
                        var column1 = obj.GetDrawingObjectParams("column1");
                        var column2 = obj.GetDrawingObjectParams("column2");
                        hts = new HTuple[] { row1, column1, row2, column2 };
                    }
                    break;
                case "circle":
                    {
                        var row = obj.GetDrawingObjectParams("row");
                        var column = obj.GetDrawingObjectParams("column");
                        var redius = obj.GetDrawingObjectParams("redius");
                        hts = new HTuple[] { row, column, redius };
                    }
                    break;


                default:
                    break;
            }
            return hts;
        }




    }
}
